/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI.Customer;

/**
 *
 * @author SIX-14
 */
public class CustomerS {

    public CustomerS() {
       }
    private ThreadSocket[] clientes=null;
    private int option=0;
    private int position=0;
    private String[] process=null;
    private Monitor monitor=null;

    public Monitor getMonitor() {
        return monitor;
    }

    public void setMonitor(Monitor monitor) {
        this.monitor = monitor;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position=position;
    }

    public String[] getProcess() {
        return process;
    }

    public void setProcess(String[] process) {
        this.process = process;
    }

    public int getOption() {
        return option;
    }

    public void setOption(int option) {
        this.option = option;
    }

    public ThreadSocket[] getClientes() {
        return clientes;
    }

    public void setClientes(ThreadSocket[] clientes) {
        this.clientes = clientes;
    }

    public synchronized void beginMonitorCostumer(String ip, String[] process){
        findPosition(ip);
                getClientes()[position].setProcess(process);
                getClientes()[position].setOption(1);
    }

    public synchronized Monitor receiveResult(String ip){
        findPosition(ip);
        Monitor monitor=null;
                getClientes()[position].setOption(2);
                monitor = getClientes()[position].getMonitor();
                while(monitor==null){
                    monitor = getClientes()[position].getMonitor();
                }
        return monitor;
    }

    public void resetMonitorCostumer(String ip){
        findPosition(ip);
        getClientes()[position].setOption(3);
    }

    public void findPosition(String ip){
        for(int i=0; i<getClientes().length; i++){
            if(getClientes()[i].getInetAddress().equals(ip)){
                setPosition(i);
                break;
            }
        }
    }

}
